<template>
  <div class="xtzxda">
    <a-search :change="paginationElement?.change" :list="list" v-model="form"></a-search>
    <a-card resize>
      <a-table :data="data" :head="head">
        <template #handle="{ row }">
          <el-link type="primary" @click="handleInfo(row)">详情</el-link>
        </template>
      </a-table>
      <a-pagination ref="paginationElement" :total="total" :change="getTableData"></a-pagination>
      <a-dialog :title="title" v-model="show" :footer="false">
        <a-form ref="formElement" :list="rowList" v-model="rowForm" :inline="true" :disabled="true"></a-form>
      </a-dialog>
    </a-card>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { tableData, info, memorandumInfoNew } from '../../api/xtzxda/xtzxda'

interface XTZXDA {
  id: string
  memorandumId: string
  [key: string]: unknown
}

const paginationElement = ref<APaginationInstance | null>()
const formElement = ref<AFormInstance | null>(null)

const form = ref({})
const list = ref<FormItem[]>([
  { prop: 'objectName', 'aria-label': '对象名称', type: 'input' },
  { prop: 'objectCodeValue', 'aria-label': '对象代码', type: 'input' }
])

const data = ref<XTZXDA[]>([])
const head = ref([
  { prop: 'objectName', label: '对象名称' },
  { prop: 'objectCodeValue', label: '对象代码' },
  { prop: 'memorandumName', label: '备忘录名称' },
  { prop: 'departmentName', label: '反馈部门' },
  { prop: 'feedbackContent', label: '反馈内容' },
  { prop: 'createTime', label: '反馈日期' },
  { prop: 'handle', label: '操作', fixed: 'right' }
])
const total = ref(0)

function getTableData(row: number, size: number) {
  tableData<XTZXDA>({
    size,
    row,
    ...form.value
  }).then(({ data: result }) => {
    data.value = result.pageList
    total.value = result.totals
  })
}

const rowForm = ref<XTZXDA>({} as XTZXDA)
const rowList = ref<FormItem[]>([
  { prop: 'objectName', 'aria-label': '对象名称', type: 'input' },
  { prop: 'departmentName', 'aria-label': '反馈部门名称', type: 'input' },
  { prop: 'objectCodeValue', 'aria-label': '对象代码', type: 'input' },
  { prop: 'memorandumName', 'aria-label': '备忘录名称', type: 'input' },
  { prop: 'matterName', 'aria-label': '名单名称', type: 'input' },
  {
    prop: 'objectType',
    'aria-label': '名单类型',
    type: 'select',
    data: [
      { label: '红名单', value: '1' },
      { label: '黑名单', value: '0' }
    ]
  },
  { prop: 'measureId', 'aria-label': '执行措施', type: 'select', data: [] },
  { prop: 'feedbackContent', 'aria-label': '反馈内容', type: 'textarea' },
  { prop: 'effect', 'aria-label': '影响', type: 'textarea' },
  { prop: 'bussinessItem', 'aria-label': '业务事项', type: 'textarea' },
  { prop: 'remark', 'aria-label': '备注', type: 'textarea' }
])

const show = ref(false)
const title = ref('详情')

function handleInfo(row: XTZXDA) {
  info<XTZXDA>(row!.id).then(({ data: result }) => {
    rowForm.value = { ...row, ...result }

    memorandumInfoNew<{ id: string; measureContent: string }[]>(row.memorandumId).then(({ data: r }) => {
      rowList.value[6].data = r.map((i) => {
        return {
          label: i.measureContent,
          value: i.id
        }
      })

      show.value = true
    })
  })
}
</script>
